<template>
  <div class="app-container">
    <div class="filter-container">
      <el-form :inline="true" :model="formModel">
        <el-form-item class="no-warn-item" label="工程整车号:" prop="vehicleNo">
          <el-input v-model="formModel.vehicleNo" disabled>
            <el-button slot="append" type="primary" icon="el-icon-search" @click="queryVehicleNo"></el-button>
          </el-input>
        </el-form-item>
        <el-form-item class="no-warn-item" label="模块:" prop="moduleCode">
          <el-select v-model="formModel.moduleCode" clearable filterable>
            <el-option v-for="item in moduleOptions" :key="item.moduleCode" :label="item.moduleCode+'-'+item.moduleDesc" :value="item.moduleCode"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item class="no-warn-item" label="识别码:" prop="markCode">
          <el-input
            v-model="formModel.markCode"
            class="filter-item "
            clearable
          />
        </el-form-item>
        <el-form-item class="no-warn-item" label="发布状态:" prop="releaseStatus">
          <hey-select v-model="formModel.releaseStatus" clcd="release_status_cd" />
        </el-form-item>
        <el-row class="submit-area">
          <el-col :span="24">
            <el-button type="primary" v-if="hasPermission('module-vehicle_select')" plain @click="queryList(false)">查询</el-button>
            <el-button type="primary" v-if="hasPermission('module-vehicle_clear')" plain @click="clearCondition">清除</el-button>
            <el-button type="primary" v-if="hasPermission('module-vehicle_add')" plain @click="handleAdd">新增</el-button>
            <el-button type="primary" v-if="hasPermission('module-vehicle_release')" plain @click="handleRelease">发布</el-button>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <hey-table ref="table" :table-data="tableData"  :columns="columns" @row-click="chooseTable" :is-radio="true">

    </hey-table>
    <el-dialog
      v-dialogDrag
      v-if="dialogVisible"
      :close-on-click-modal="false"
      title="工程号与模块信息"
      :visible.sync="dialogVisible"
      width="70%"
    >
      <module-vehicle-mnt :page-type="operType" :edit-data="editData" @mntSuc="queryList" />
    </el-dialog>

    <el-dialog
      v-dialogDrag
      v-if="showVehicleNo"
      :close-on-click-modal="false"
      title="工程整车号信息"
      :visible.sync="showVehicleNo"
      width="90%"
      append-to-body
    >
      <material-vehicle-dialog @queryVehicleNoSuc="queryVehicleNoSuc" />
    </el-dialog>

  </div>
</template>

<script>

  export default {
    name: 'ModuleVehicleList',
    components: {
      ModuleVehicleMnt: () => import('./module-vehicle-mnt'),
      MaterialVehicleDialog: () => import('@/views/dialog/material-vehicle-dialog'),
    },
    props: {},
    data() {
      return {
        dialogVisible: false,
        showVehicleNo:false,
        operType: '',
        editData: {},
        chooseData: {},
        tableData:[],
        moduleOptions:[],
        formModel: {
          vehicleNo: '',
          tmBasModuleId: '',
          markCode: '',
          releaseStatus: '',
          isDelete: '0'
        },
        columns: [
          { title: '工程整车号', key: 'vehicleNo'},
          { title: '模块代码', key: 'moduleCode'},
          { title: '模块描述', key: 'moduleDesc'},
          { title: '识别码', key: 'markCode'},
          { title: '发布状态', key: 'releaseStatus',clcd:'release_status_cd' },
          { title: '发布时间', key: 'releaseTime' },
          { title: '发布用户', key: 'releaseUsername' },
          { title: '创建时间', key: 'createTime' },
          { title: '创建人', key: 'createUsername' },
          { title: '最后修改时间', key: 'lastUpdateTime'},
          { title: '最后修改人', key: 'lastUpdateUsername' },
        ]
      }
    },
    computed: {

    },
    mounted() {
      this.getModule()
    },
    methods: {
      chooseTable(row){
        if(row){
          this.chooseData = row
        }else{
          this.chooseData = {}
        }
      },
      getModule(){
        const param = {pageNum:1,pageSize:9999}
        param.isDelete = '0'
        this.get('/tmBasModule/queryTmBasModule', param).then(res => {
          this.moduleOptions = res.list
        })
      },
      clearCondition(){
        this.resetObj(this.formModel)
        this.formModel.isDelete = '0'
      },
      queryVehicleNo(){
        this.showVehicleNo = true
      },
      queryVehicleNoSuc(data){
        this.formModel.vehicleNo = data.vehicleNo
      },
      queryList() {
        this.$refs.table.query('/trBasMaterialModule/queryTrBasMaterialModule', this.formModel, '', false)
      },
      handleAdd() {
        this.operType = 'add'
        this.dialogVisible = true
      },
      handleRelease() {
        if(Object.keys(this.chooseData).length==0){
          this.$warn('请先选中一条详细信息列表中的数据!')
          return false
        }
        if(!this.hasAuthority(this.chooseData.tmBasModuleId)){
          this.$warn('用户不具有操作该模块的业务权限,请配置业务权限!')
          return false
        }
        if(this.chooseData.releaseStatus=='3'){
          this.$warn('该数据为历史版本,不能进行发布!')
          return false
        }
        if(this.chooseData.releaseStatus=='2'){
          this.$warn('该数据已发布,不能重复发布!')
          return false
        }
        const param = {}
        const operateType = '09'
        param.operateType = operateType
        param.rcrdId = this.chooseData.rcrdId
        param.vehicleNo = this.chooseData.vehicleNo
        param.markCode = this.chooseData.markCode
        param.tmBasModuleId = this.chooseData.tmBasModuleId
        const url = '/trBasMaterialModule/maintainTrBasMaterialModule'
        const tip = '发布成功!'
        this.post(url, param).then(res => {
          this.$info(tip, () => {
            this.queryList()
          })
        })
      },
    }
  }
</script>


